package com.haiqiu.file.local.config;

import com.haiqiu.file.local.utils.ServerFileUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author HaiQiu
 * @since 2023/3/8
 */
@Component
@ConfigurationProperties(prefix = "local.server")
public class LocalConfig {

    /**
     * 是否启用本地文件服务
     */
    private Boolean enable = false;

    /**
     * 服务器映射的地址+端口
     */
    private String server = "http://localhost:8080";

    /**
     * 文件父级存储路径
     */
    private String parent = "C:\\";

    /**
     * 文件资源虚拟映射路径
     * 列如访问一个文件就是：localhost:8080/resource/文件绝对路径
     * demo: localhost:8080/resource/aaa/123.png
     */
    private String virtual = "/resource";

    public Boolean getEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    public String getServer() {
        return server;
    }

    public void setServer(String server) {
        this.server = server;
    }

    public String getParent() {
        return parent;
    }

    public void setParent(String parent) {
        this.parent = parent;
    }

    public String getVirtual() {
        return virtual;
    }

    public void setVirtual(String virtual) {
        this.virtual = virtual;
    }

    /**
     * 初始化本地服务文件上传服务
     */
    @PostConstruct
    public void initLocal(){
        ServerFileUtils.init(this);
    }

}
